using System;
using System.Collections.Generic;
using System.Text;

namespace Acms.AcmsControls
{
    public class ImageContentControlDisplay : BaseContentControlDisplay
    {
        private AcmsImage image = new AcmsImage();

        protected override void CreateChildControls()
        {
            this.Controls.Add(image);
            base.CreateChildControls();
        }
        private ImageContentControlProperties properties;
        protected ImageContentControlProperties Properties
        {
            get
            {
                if (properties == null)
                {
                    properties = new ImageContentControlProperties();
                }
                return properties;
            }
        }

        protected override BaseContentControlProperties GetProperties()
        {
            return Properties;
        }

        protected override void SetProperties(BaseContentControlProperties properties)
        {
            this.properties = properties as ImageContentControlProperties;
        }

        protected override void DataBindChildren()
        {
            image.FileId = Properties.ResourceId;
            image.RenderHeight = this.RenderHeight;
            image.RenderWidth = this.RenderWidth;
            image.AlternateText = Properties.AltText;
        }

        private int renderHeight;
        public int RenderHeight
        {
            get { return renderHeight; }
            set { renderHeight = value; }
        }

        private int renderWidth;
        public int RenderWidth
        {
            get { return renderWidth; }
            set { renderWidth = value; }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (this.image == null || this.image.FileId == null || this.image.FileId == 0)
            {
                this.Visible = false;
            }
        }
    }
}
